package com.design.patterns.structuralModel.iterator.service.file;

import com.design.patterns.structuralModel.iterator.service.ProfileIterator;
import com.design.patterns.structuralModel.iterator.service.bean.Profile;

import java.util.ArrayList;
import java.util.List;

public class WeChatIterator implements ProfileIterator {
    Integer prosum = 0;
    List<Profile> prifiles =  new ArrayList<>();

    public WeChatIterator(List<Profile> prifiles) {
        this.prifiles = prifiles;
    }

    @Override
    public boolean hasNext() {
//        return prifiles.size() - 1 <= prosum;
        return prifiles.size() - 1 <= prosum;
    }

    @Override
    public Profile getNext() {
        if (! hasNext()){
            return null;
        }
        Profile profile = prifiles.get(prosum);
        prosum++;
        return profile;
    }

    @Override
    public void reset() {
        prosum = 0;
    }
}
